package com.sinopec.handdevice.presenter

import com.sinopec.basemodule.api.BaseModuleApi
import com.sinopec.basemodule.http.CommonObserver
import com.sinopec.basemodule.http.ExceptionEngine
import com.sinopec.basemodule.model.ErrorPalletCodeResultModel
import com.sinopec.basemodule.model.StockInListModel
import com.sinopec.handdevice.contract.StockInListContract

/**
 * @author lwj
 * @ClassName: StockInPresenter
 * @Description: 入库-入库列表
 */
class StockInListPresenter(view: StockInListContract.View?) :
    StockInListContract.Presenter(view!!) {

    override fun stockInList(machineCode: String) {
        val resultObservable = BaseModuleApi.stockInList(machineCode)
        toSubscribe(
            resultObservable,
            object : CommonObserver<List<StockInListModel>>(mView.context) {
                override fun onNext(list: List<StockInListModel>) {
                    mView.refreshUI(getData())
                }

                override fun onError(t: ExceptionEngine.ResponseThrowable) {
                    mView.refreshUI(getData())
                    //mView.showMessage(t.message)
                }
            })
    }

    /**
     * @author lwj
     * @Description:测试数据
     */
    private fun getData(): List<StockInListModel> {
        val list: MutableList<StockInListModel> = ArrayList()
        for (i in 1..9) {
            val model = StockInListModel()
            //任务id
            model.taskRecordId = "1000$i".toLong()
            //任务单号
            model.taskNo = "LJ100203023$i"
            //仓库名称-库位名称
            model.locationName = "镇海AB库" + 1
            //物料名称
            model.mtrlName = "聚丙烯颗粒" + 1
            //预计总重量（吨）
            model.expectedPalletQuantity = "100$i".toBigDecimal()
            //机器码，（移动机器人使用）
            model.machineCode = "00$i"
            //车牌号
            model.taskPriority = "$i".toInt()
            //已读有效托盘code集合 ,ArrayList
            val palletCodes: ArrayList<String> = ArrayList()
            palletCodes.add("86 10 81 42 B0 5D")
            palletCodes.add("86 10 81 42 B0 5E")
            palletCodes.add("86 10 81 42 B0 5F")

//            for (j in 10..50) {
//                palletCodes.add("87 11 22 33 44 $j")
//            }
            model.palletCodes = palletCodes
            list.add(model)
        }
        return list
    }
}